package novatel

import (
	"dgo/goutils/gnss"
	"encoding/binary"
	"math"
)

var (
	MAXVAL float64 = 8388608.0
)

func ByteToFloat64(bytes []byte) float64 {
	bits := binary.LittleEndian.Uint64(bytes)
	return math.Float64frombits(bits)
}

func ByteToFloat32(bytes []byte) float32 {
	bits := binary.LittleEndian.Uint32(bytes)
	return math.Float32frombits(bits)
}

func ToNaviSys(v byte) byte {
	switch v {
	case 0:
		return gnss.SYS_GPS
	case 1:
		return gnss.SYS_GLO
	case 2:
		return gnss.SYS_SBS
	case 3:
		return gnss.SYS_GAL
	case 4:
		return gnss.SYS_BD
	case 5:
		return gnss.SYS_QZS
	case 7:
		return gnss.SYS_WLNAV
	}
	return gnss.SYS_UNKOWN
}

/*
*
 */
func RangecmpToYObsSignID(navisys byte, signv byte) (freq byte, rval byte) {
	freq = 0
	rval = 0
	if navisys == gnss.SYS_GPS {
		//  case  0: freq=0; *code=CODE_L1C; break; /* L1C/A */
		//	case  5: freq=0; *code=CODE_L1P; break; /* L1P */
		//	case  9: freq=1; *code=CODE_L2D; break; /* L2Pcodeless */
		//	case 14: freq=2; *code=CODE_L5Q; break; /* L5Q (OEM6) */
		//	case 17: freq=1; *code=CODE_L2X; break; /* L2C(M+L) */
		switch signv {
		case 0:
			freq = 0
			rval = gnss.YOBS_GPS_SIGN_L1_1C
		case 2:
			rval = gnss.YOBS_GPS_SIGN_L5_5Q
		case 3:
			rval = gnss.YOBS_GPS_SIGN_L1_1L // unicore
		case 5:
			freq = 1
			rval = gnss.YOBS_GPS_SIGN_L2_2P
		case 9:
			freq = 1
			rval = gnss.YOBS_GPS_SIGN_L2_2W
		case 14:
			freq = 2
			rval = gnss.YOBS_GPS_SIGN_L5_5Q
		case 17:
			freq = gnss.FREQ_GPS_TYPE_L2
			rval = gnss.YOBS_GPS_SIGN_L2_2S
		}
	} else if navisys == gnss.SYS_BD {
		switch signv {
		case 0:
			freq = gnss.FREQ_BD_BAND_TYPE_B1I
			rval = gnss.YOBS_BDS_SIGN_B1_2I
		case 17:
			freq = gnss.FREQ_BD_BAND_TYPE_B2I
			rval = gnss.YOBS_BDS_SIGN_B2_7I
		case 2:
			freq = gnss.FREQ_BD_BAND_TYPE_B3I
			rval = gnss.YOBS_BDS_SIGN_B3_6I
		case 8: // zjy
			freq = gnss.FREQ_BD_BAND_TYPE_B1C
			rval = gnss.YOBS_BDS_SIGN_B1C_1D
		case 21: // zjy
			freq = gnss.FREQ_BD_BAND_TYPE_B3I
			rval = gnss.YOBS_BDS_SIGN_B3_6I
		case 12: // zjy
			freq = gnss.FREQ_BD_BAND_TYPE_B2A
			rval = gnss.YOBS_BDS_SIGN_B2A_5D
		}
	} else if navisys == gnss.SYS_GLO {
		switch signv {
		case 0:
			freq = gnss.FREQ1_GLO_TYPE_G1
			rval = gnss.YOBS_GLO_SIGN_G1_1C
		case 1:
			freq = gnss.FREQ1_GLO_TYPE_G2
			rval = gnss.YOBS_GLO_SIGN_G2_2C
		case 5:
			freq = gnss.FREQ1_GLO_TYPE_G2
			rval = gnss.YOBS_GLO_SIGN_G2_2P
		}
	} else if navisys == gnss.SYS_SBS {
		switch signv {
		case 0:
			freq = gnss.FREQ_SBAS_TYPE_L1
			rval = gnss.YOBS_GLO_SIGN_G2_2P
		}
	} else if navisys == gnss.SYS_GAL {
		switch signv {
		case 2: // zjy
			freq = gnss.FREQ_GAL_TYPE_E1
			rval = gnss.YOBS_GAL_SIGN_E1_1C
		case 12: // zjy
			freq = gnss.FREQ_GAL_TYPE_E5A
			rval = gnss.YOBS_GAL_SIGN_E5A_5Q
		case 17: // zjy
			freq = gnss.FREQ_GAL_TYPE_E5B
			rval = gnss.YOBS_GAL_SIGN_E5B_7Q
		}
	} else if navisys == gnss.SYS_WLNAV {

	}
	return
}
